/**
 * Created by wang.cheng on 2016/1/5.
 */
var splashScreenService = require('../../../services/mis/master/splashScreenService.js');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');
exports.splashScreenList = function (req, res) {
    splashScreenService.splashScreenList(req, function (err, results) {
        if (err) {
            logger.error('Exception happen when exchangeListService...' + err);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when splashScreenList...'));
        } else {
            var data = {
                count: results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            logger.debug("listSplashScreen "+data);

            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }
    });
};


exports.addSplashScreen = function (req, res) {
    splashScreenService.addSplashScreen(req,function (err, results) {
            if (err) {
                logger.error('Exception happen when exchangeListService...' + err);
                res.json(messageUtil.composeFailedMessage(req,  err));
            } else {
                logger.debug("listSplashScreen "+results);
                res.json(messageUtil.composeSucceededMessage(req, null, null));
            }
        });
};

exports.splashScreenDel = function(req,res)
{
    splashScreenService.delSplashScreen(req,function(err,results)
    {
        if (err) {
            logger.error('Exception happen when exchangeListService...');
            res.json(messageUtil.composeFailedMessage(req, err));
        } else {
            logger.debug("listSplashScreen "+results);
            res.json(messageUtil.composeSucceededMessage(req, null, null));
        }
    });
}

exports.splashScreenEdit = function(req,res)
{
    splashScreenService.updateSplashScreen(req,function(err,results)
    {
        if (err) {
            logger.error('Exception happen when splashScreenEdit...');
            try {
                if(err.message)
                    err.message = err;
            }catch (exception)
            {
                err = {};
                err.message = "未知错误";
            }
            res.json(messageUtil.composeFailedMessage(req, err));
        } else {
            logger.debug("listSplashScreen "+results);
            res.json(messageUtil.composeSucceededMessage(req, null, null));
        }
    });
}

exports.splashScreenLatestStartDate = function(req,res)
{
    splashScreenService.splashScreenLatestStartDate(function(err,results)
    {
        if(err)
        {
            logger.error('Exception happen when exchangeListService...' + err);
            res.json(messageUtil.composeFailedMessage(req, err));
        }else
        {
            logger.debug("listSplashScreen "+results);
            res.json(messageUtil.composeSucceededMessage(req, null, results.endDate));
        }
    });
};

exports.splashScreenValuateDateOverlap = function(req,res)
{
    splashScreenService.validateDateOverlap(req.body.startDate,req.body.endDate,function(err,results)
    {
        if(err)
        {
            logger.error('Exception happen when splashScreenValuateDate...' + err);
            res.json(messageUtil.composeFailedMessage(req, err));
        }else
        {
            logger.debug("listSplashScreen "+results);
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }
    });
}